﻿using System.Data;
using System.Windows.Forms;
using ApplicationLibrary.DBManager;
using ApplicationLibrary.ExtendedControls;
using Vintner.Items.ModuleData;

namespace Vintner.Items.Library
{
    internal class ItemsCreator : Vintner.Items.Forms.Items, IDocumentDataManager
    {
        public ItemsCreator()
        {
        }

        public bool Find(string code)
        {
            RadarItemsParam param = new RadarItemsParam(code);
            return FindRecord(param);
        }

        public void SetData1(string code, string descr, double qty)
        {
            Controls["codItem"].Text = code;
            Controls["txtDescription"].Text = descr;
            ((NumericTextBox)Controls["ntbSize"]).NumericValue = (decimal)qty;
        }

        public void AddPrice(string cat, double price, string taxCode)
        {
            ExtendedDataGridView dgw = (ExtendedDataGridView)Controls["tabControl1"].Controls["tbpPrice"].Controls["dgwPrice"];

            foreach (DataGridViewRow dr in dgw.Rows)
            {
                if (DataGridViewRowValues.GetValue<string>(dr, VI_ItemsPrice.Category) == cat)
                    return;
            }
            DataRowView drw = dgw.AddNewRow();
            DataRowViewValues.SetValue<string>(drw, VI_ItemsPrice.Category, cat);
            DataRowViewValues.SetValue<double>(drw, VI_ItemsPrice.Price, price);
            DataRowViewValues.SetValue<string>(drw, VI_ItemsPrice.TaxCode, taxCode);
        }
    }
}